package com.liangchen.astools.core

import android.os.*
import androidx.annotation.RequiresApi
import com.liangchen.astools.memtracker.Memtracker
import com.liangchen.astools.utils.AsLog.i

class AsWorkerThread(name: String?) : HandlerThread(name) {
    var mMainHandler: Handler? = null
    override fun run() {
        super.run()
    }

    class WorkerHandler(thread: HandlerThread) : Handler() {
        @RequiresApi(api = Build.VERSION_CODES.M)
        override fun handleMessage(msg: Message) {
            super.handleMessage(msg)
            when (msg.what) {
                MSG_START_TRACK_MEM_PSS -> {
                   i("cdgaslog", "start track memory!")
                    val valueMap = Memtracker.trackMemoryOnce()
                }
                else ->  i("cdgaslog", "wrong code")
            }
        }

        init {
            Companion.looper = thread.looper
        }

        companion object {
            private lateinit var looper: Looper
        }
    }

    companion object {
        const val MSG_START_TRACK_MEM_PSS = 0x1001
    }
}